package stream;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * flatmap使用
 * @Description:
 * @author wanglong
 * @createDate: 2019年3月19日 下午11:15:12
 */
public class Demo2 {

	public static void main(String[] args) {
		
		
		String[] strings = {"hello","world"};
		
		/**
		 * 得到{"H", "e", "l", "l", "o", "w", "o", "r", "l", "d"}
		 */
		
		List<String[]> xStrings = Arrays.asList(strings).stream().map(str -> str.split("")).collect(Collectors.toList());
		xStrings.forEach(System.out::println);
		//拿到"hello","world" List
		Stream<String[]> stream = Arrays.asList(strings).stream().
				map(str -> str.split(""));
		Stream<Stream<String>> streamStream = stream.map(strs -> Arrays.stream(strs));
		List<Stream<String>> streamList = streamStream.collect(Collectors.toList());
		
		/**
		 * 方法二
		 */
		List<String> result = Arrays.asList(strings).stream().
				map(str -> str.split("")).
				flatMap(str -> Arrays.stream(str)).
				collect(Collectors.toList());
		
		result.forEach(System.out::println);
		
		
	}
}
